From 05460f49827c7f362c58aafb3ba844d5ba334da0 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Wed, 8 Oct 2014 03:26:01 +0200 Subject: [PATCH] render: Make rendering the background a single function --- gtk/gtkrender.c | 24 ++++------ gtk/gtkthemingbackground.c | 79 +++++++++++++++---------------- gtk/gtkthemingbackgroundprivate.h | 33 +++---------- 3 files changed, 54 insertions(+), 82 deletions(-) diff --git a/gtk/gtkrender.c b/gtk/gtkrender.c index 28487bde5f..a7f7bef281 100644 --- a/gtk/gtkrender.c +++ b/gtk/gtkrender.c @@ -492,14 +492,11 @@ gtk_do_render_background (GtkStyleContext *context, gdouble width, gdouble height) { - GtkThemingBackground bg; - - _gtk_theming_background_init (&bg, context, - x, y, - width, height, - gtk_style_context_get_junction_sides (context)); - - _gtk_theming_background_render (&bg, cr); + gtk_theming_background_render (context, + cr, + x, y, + width, height, + gtk_style_context_get_junction_sides (context)); } /** @@ -1580,7 +1577,6 @@ gtk_do_render_extension (GtkStyleContext *context, gdouble height, GtkPositionType gap_side) { - GtkThemingBackground bg; GtkJunctionSides junction = 0; guint hidden_side = 0; @@ -1604,11 +1600,11 @@ gtk_do_render_extension (GtkStyleContext *context, break; } - _gtk_theming_background_init (&bg, context, - x, y, - width, height, - junction); - _gtk_theming_background_render (&bg, cr); + gtk_theming_background_render (context, + cr, + x, y, + width, height, + junction); render_frame_internal (context, cr, x, y, width, height, diff --git a/gtk/gtkthemingbackground.c b/gtk/gtkthemingbackground.c index f622a43657..e2b251b89f 100644 --- a/gtk/gtkthemingbackground.c +++ b/gtk/gtkthemingbackground.c @@ -43,6 +43,20 @@ */ #include "fallback-c89.c" +typedef struct _GtkThemingBackground GtkThemingBackground; + +struct _GtkThemingBackground { + GtkStyleContext *context; + + cairo_rectangle_t paint_area; + GtkRoundedBox border_box; + GtkRoundedBox padding_box; + GtkRoundedBox content_box; + + GtkJunctionSides junction; + GdkRGBA bg_color; +}; + static const GtkRoundedBox * gtk_theming_background_get_box (GtkThemingBackground *bg, GtkCssArea area) @@ -308,63 +322,44 @@ _gtk_theming_background_init_context (GtkThemingBackground *bg) } void -_gtk_theming_background_init (GtkThemingBackground *bg, - GtkStyleContext *context, - gdouble x, - gdouble y, - gdouble width, - gdouble height, - GtkJunctionSides junction) +gtk_theming_background_render (GtkStyleContext *context, + cairo_t *cr, + gdouble x, + gdouble y, + gdouble width, + gdouble height, + GtkJunctionSides junction) { - g_assert (bg != NULL); - - bg->context = context; + GtkThemingBackground bg; + gint idx; + GtkCssValue *background_image; - bg->paint_area.x = x; - bg->paint_area.y = y; - bg->paint_area.width = width; - bg->paint_area.height = height; + bg.context = context; - bg->junction = junction; + bg.paint_area.x = x; + bg.paint_area.y = y; + bg.paint_area.width = width; + bg.paint_area.height = height; - _gtk_theming_background_init_context (bg); -} + bg.junction = junction; -void -_gtk_theming_background_render (GtkThemingBackground *bg, - cairo_t *cr) -{ - gint idx; - GtkCssValue *background_image; + _gtk_theming_background_init_context (&bg); - background_image = _gtk_style_context_peek_property (bg->context, GTK_CSS_PROPERTY_BACKGROUND_IMAGE); + background_image = _gtk_style_context_peek_property (bg.context, GTK_CSS_PROPERTY_BACKGROUND_IMAGE); cairo_save (cr); - cairo_translate (cr, bg->paint_area.x, bg->paint_area.y); + cairo_translate (cr, bg.paint_area.x, bg.paint_area.y); - _gtk_theming_background_apply_shadow (bg, cr, FALSE); /* Outset shadow */ + _gtk_theming_background_apply_shadow (&bg, cr, FALSE); /* Outset shadow */ - _gtk_theming_background_paint_color (bg, cr, background_image); + _gtk_theming_background_paint_color (&bg, cr, background_image); for (idx = _gtk_css_array_value_get_n_values (background_image) - 1; idx >= 0; idx--) { - _gtk_theming_background_paint_layer (bg, idx, cr); + _gtk_theming_background_paint_layer (&bg, idx, cr); } - _gtk_theming_background_apply_shadow (bg, cr, TRUE); /* Inset shadow */ + _gtk_theming_background_apply_shadow (&bg, cr, TRUE); /* Inset shadow */ cairo_restore (cr); } - -gboolean -_gtk_theming_background_has_background_image (GtkThemingBackground *bg) -{ - GtkCssImage *image; - GtkCssValue *value = _gtk_style_context_peek_property (bg->context, GTK_CSS_PROPERTY_BACKGROUND_IMAGE); - - if (_gtk_css_array_value_get_n_values (value) == 0) - return FALSE; - - image = _gtk_css_image_value_get_image (_gtk_css_array_value_get_nth (value, 0)); - return (image != NULL); -} diff --git a/gtk/gtkthemingbackgroundprivate.h b/gtk/gtkthemingbackgroundprivate.h index cb1f600093..eebf2e5322 100644 --- a/gtk/gtkthemingbackgroundprivate.h +++ b/gtk/gtkthemingbackgroundprivate.h @@ -29,32 +29,13 @@ G_BEGIN_DECLS -typedef struct _GtkThemingBackground GtkThemingBackground; - -struct _GtkThemingBackground { - GtkStyleContext *context; - - cairo_rectangle_t paint_area; - GtkRoundedBox border_box; - GtkRoundedBox padding_box; - GtkRoundedBox content_box; - - GtkJunctionSides junction; - GdkRGBA bg_color; -}; - -void _gtk_theming_background_init (GtkThemingBackground *bg, - GtkStyleContext *context, - gdouble x, - gdouble y, - gdouble width, - gdouble height, - GtkJunctionSides junction); - -void _gtk_theming_background_render (GtkThemingBackground *bg, - cairo_t *cr); - -gboolean _gtk_theming_background_has_background_image (GtkThemingBackground *bg); +void gtk_theming_background_render (GtkStyleContext *context, + cairo_t *cr, + gdouble x, + gdouble y, + gdouble width, + gdouble height, + GtkJunctionSides junction); G_END_DECLS -- 2.30.2